using System.Collections;
using UnityEngine;
using UnityEngine.Audio;

public class ChristmasSleighAudio : MonoBehaviour
{
	public AudioSource oneAudioSource;

	public AudioSource stopAudioSource;

	public AudioMixerSnapshot oleninaSnapshot;

	public AudioMixerSnapshot stopSnapshot;

	public AudioMixerSnapshot mainSnapshot;

	public float distancePlay;

	public NavigationBySeveralPoints curZeppelin;

	private bool inTrigger;

	private void Start()
	{
		curZeppelin.OnStayPointNear += ChangeStopState;
		StartCoroutine(CheckDistance());
	}

	private IEnumerator CheckDistance()
	{
		while (true)
		{
			if (GameController.instance.playerScript == null)
			{
				yield return null;
				continue;
			}
			float distance = Vector3.Distance(GameController.instance.playerScript.transform.position, base.transform.position);
			if (inTrigger && distance > distancePlay)
			{
				TriggerExit();
			}
			else if (!inTrigger && distance < distancePlay)
			{
				TriggerEnter();
			}
			if ((inTrigger && GameController.instance.playerScript.inCar) || GameController.instance.playerScript.inHelic)
			{
				TriggerExit();
			}
			yield return new WaitForSeconds(0.5f);
		}
	}

	private void TriggerEnter()
	{
		if (!GameController.instance.playerScript.inCar && !GameController.instance.playerScript.inHelic)
		{
			oneAudioSource.enabled = true;
			stopAudioSource.enabled = true;
			oleninaSnapshot.TransitionTo(5f);
			inTrigger = true;
		}
	}

	private void TriggerExit()
	{
		oneAudioSource.enabled = false;
		stopAudioSource.enabled = false;
		inTrigger = false;
		if (!GameController.instance.playerScript.inCar && !GameController.instance.playerScript.inHelic)
		{
			mainSnapshot.TransitionTo(5f);
		}
	}

	private void ChangeStopState(bool enable)
	{
		if (inTrigger)
		{
			if (enable)
			{
				stopSnapshot.TransitionTo(10f);
			}
			else
			{
				oleninaSnapshot.TransitionTo(5f);
			}
		}
	}
}
